<?php
class user { 
    var $user_id;
    var $user_name;
    var $user_fname;
    var $user_lname;
    var $user_uname;
    var $user_sys_name;
    var $user_password;
    var $user_mail;
    var $user_fb_link;
    var $user_profile_pic;
    var $user_g_id;
    var $user_ut_id;
    var $user_birthday;
    var $user_register_date;
    var $user_status;


    function actualizarMail(){
        include_once 'bd_conn_class/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " UPDATE user SET user_mail_temp = '".$this->user_mail."', user_mail_temp_date = NOW() WHERE user_id = '".$this->user_id."' " ;
        
        $rs = $DB->EjecutarQuery($query);
        $DB->DesconectarBD();        
        return $rs; 
    }
    
    function actualizarBirthday(){
        include_once 'bd_conn_class/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " update user set user_birthday = '".$this->user_birthday."' where user_id = '".$this->user_id."' " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs; 
    }

    function actualizarUserSystemName(){
        include_once 'bd_conn_class/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " update user set user_sys_name = '".$this->user_sys_name."' where user_id = '".$this->user_id."' " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs; 
    }
    
    function confirmarMail(){
        include_once 'bd_conn_class/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " UPDATE user SET user_mail = '".$this->user_mail."', user_mail_temp = '', user_mail_temp_date = '0000-00-00 00:00:00' WHERE user_mail_temp = '".$this->user_mail."' " ;
        
        $rs = $DB->EjecutarQuery($query);
        $DB->DesconectarBD();        
        return $rs; 
    }    
    
    function Delete(){
        
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $q = " select user_status from user where user_id ='".$this->user_id."' " ;
        $rse = $DB->ObtenerData($q);   
        
        if($rse[0]["user_status"]==0){
            $this->user_status = 1;
        }else{
            $this->user_status = 0;
        }
        
        $query = " UPDATE estado SET
                     user_status='".$this->user_status."'
                     where user_id ='".$this->user_id."' " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function Update(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function GetData(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
         
        $query = " Select * from user where user_id ='".$this->user_id."' ";
        $rs = $DB->ObtenerData($query, "user" );

        $this->user_id = $rs[0]["user_id"];
        $this->user_name = $rs[0]["user_name"];
        $this->user_fname = $rs[0]["user_fname"];
        $this->user_lname = $rs[0]["user_lname"];
        $this->user_uname = $rs[0]["user_uname"];
        $this->user_mail = $rs[0]["user_mail"];
        $this->user_fb_link = $rs[0]["user_fb_link"];
        $this->user_profile_pic = $rs[0]["user_profile_pic"];
        $this->user_g_id = $rs[0]["user_g_id"];
        $this->user_ut_id = $rs[0]["user_ut_id"];
        $this->user_birthday = $rs[0]["user_birthday"];
        $this->user_status = $rs[0]["user_status"];

        $DB->DesconectarBD();        
    }

    function Save(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $query = " INSERT INTO user (
                     user_id, user_name, user_fname, user_lname, user_uname, user_mail, user_fb_link, user_profile_pic, user_g_id, user_ut_id, user_birthday, user_status)
                    VALUES (NULL, '$this->user_name', '$this->user_fname', '$this->user_lname', '$this->user_uname', '$this->user_mail', '$this->user_fb_link', '$this->user_profile_pic', '$this->user_g_id', '$this->user_ut_id', '$this->user_birthday', '$this->user_status');" ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;        
    }
    
    function GetList($vals = false, $orderby = false, $lim= false){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        if ($_REQUEST["seccion"] == "user" ) { //modulo user
        
            if(!isset($_REQUEST["li"])){
                $li = 0;
            }else{
                $li = $_REQUEST["li"];
            }               

            if(isset($_REQUEST["page"])){
                $li = ($_REQUEST["page"]* $_SESSION['PREF']['LIST_LIMIT'])- $_SESSION['PREF']['LIST_LIMIT'];
            }

            if(!$vals){
                $vals = " * ";            
            }

            if(!$lim){
                $limit ="LIMIT ".$li.", ".$_SESSION['PREF']['LIST_LIMIT']." ";
            }

            if($orderby){            
                $order =" ORDER BY $orderby ";
            }else{
                $order =" ORDER BY user_status desc,  asc ";
            }

            if(isset($_REQUEST["estado"]) && $_REQUEST["estado"] <> 99 ){ 
                $where .= " and user_status = ".$_REQUEST["estado"]."  ";
            }   

            if($_REQUEST["filtro"]){
                $query = " Select $vals from user where  like '%".$_REQUEST["filtro"]."%' $where
                                $order  $limit ";
            }else{
                $query = " Select $vals from user where 1=1 $where   $order  $limit   ";
            }
            
        } else {  //desde fuera del MODULO USER
            
             $query = " Select $vals from user where user_status = 1 $where  ";
            
        }
        
        $rs = $DB->ObtenerData($query, "user");

        if (trim($vals) != "count(*)"){

            foreach ($rs as $key => $val) {
                $u = new user();
                $u->set_user_id($val["user_id"]);
                $u->set_user_name($val["user_name"]);
                $u->set_user_fname($val["user_fname"]);
                $u->set_user_lname($val["user_lname"]);
                $u->set_user_uname($val["user_uname"]);
                $u->set_user_mail($val["user_mail"]);
                $u->set_user_fb_link($val["user_fb_link"]);
                $u->set_user_profile_pic($val["user_profile_pic"]);
                $u->set_user_g_id($val["user_g_id"]);
                $u->set_user_ut_id($val["user_ut_id"]);
                $u->set_user_birthday($val["user_birthday"]);
                $u->set_user_status($val["user_status"]);
                $rs2[] = $u;
            }

            $rs = $rs2;

            include_once 'recursos/funciones.php';
            $e = getEstado();        
            if(is_array($rs)){
                foreach ($rs as $key => $value) {
                    if ($value["user_status"] == 1) {
                        $rs[$key]["user_status"] = "<img src='images/png/estado_habilitado.png' />".$e[$value["user_status"]];
                    } else {
                        $rs[$key]["user_status"] = "<img src='images/png/estado_deshabilitado.png' />".$e[$value["user_status"]];
                    }  
                }
            }
        }
        $DB->DesconectarBD();      
        return $rs;                
    }

    function get_user_id(){
        return $this->user_id;
    }
    function set_user_id($val){
        $this->user_id = $val;
    }

    function get_user_name(){
        return $this->user_name;
    }
    function set_user_name($val){
        $this->user_name = $val;
    }

    function get_user_fname(){
        return $this->user_fname;
    }
    function set_user_fname($val){
        $this->user_fname = $val;
    }

    function get_user_lname(){
        return $this->user_lname;
    }
    function set_user_lname($val){
        $this->user_lname = $val;
    }

    function get_user_uname(){
        return $this->user_uname;
    }
    function set_user_uname($val){
        $this->user_uname = $val;
    }

    function get_user_mail(){
        return $this->user_mail;
    }
    function set_user_mail($val){
        $this->user_mail = $val;
    }

    function get_user_fb_link(){
        return $this->user_fb_link;
    }
    function set_user_fb_link($val){
        $this->user_fb_link = $val;
    }

    function get_user_profile_pic(){
        return $this->user_profile_pic;
    }
    function set_user_profile_pic($val){
        $this->user_profile_pic = $val;
    }

    function get_user_g_id(){
        return $this->user_g_id;
    }
    function set_user_g_id($val){
        $this->user_g_id = $val;
    }

    function get_user_ut_id(){
        return $this->user_ut_id;
    }
    function set_user_ut_id($val){
        $this->user_ut_id = $val;
    }

    function get_user_birthday(){
        return $this->user_birthday;
    }
    function set_user_birthday($val){
        $this->user_birthday = $val;
    }

    function get_user_register_date(){
        return $this->user_register_date;
    }
    function set_user_register_date($val){
        $this->user_register_date = $val;
    }

    function get_user_status(){
        return $this->user_status;
    }
    function set_user_status($val){
        $this->user_status = $val;
    }
    
    function get_user_sys_name(){
        return $this->user_sys_name;
    }
    function set_user_sys_name($val){
        $this->user_sys_name = $val;
    }    
    
    function get_user_password(){
        return $this->user_password;
    }
    function set_user_password($val){
        $this->user_password = $val;
    }     

}